package v1alpha1

import (
	"unsafe"

	v1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/conversion"
	"k8s.io/apimachinery/pkg/runtime"

	"volcano.sh/volcano/pkg/apis/scheduling"
)

func init() {
	localSchemeBuilder.Register(addConversionFuncs)
}

func addConversionFuncs(scheme *runtime.Scheme) error {
	// Add non-generated conversion functions to handle the *int32 -> int32
	// conversion. A pointer is useful in the versioned type so we can default
	// it, but a plain int32 is more convenient in the internal type. These
	// functions are the same as the autogenerated ones in every other way.
	err := scheme.AddConversionFuncs(
		Convert_scheduling_QueueStatus_To_v1alpha1_QueueStatus,
		Convert_scheduling_QueueSpec_To_v1alpha1_QueueSpec,
	)
	if err != nil {
		return err
	}

	return nil
}

func Convert_scheduling_QueueStatus_To_v1alpha1_QueueStatus(in *scheduling.QueueStatus, out *QueueStatus, s conversion.Scope) error {
	out.Unknown = in.Unknown
	out.Pending = in.Pending
	out.Running = in.Running
	return nil
}

func Convert_scheduling_QueueSpec_To_v1alpha1_QueueSpec(in *scheduling.QueueSpec, out *QueueSpec, s conversion.Scope) error {
	out.Weight = in.Weight
	out.Capability = *(*v1.ResourceList)(unsafe.Pointer(&in.Capability))
	return nil
}
